package libs.utils
{
	public static class Utiils
	{
		public static function Utiils()
		{
		}
		
		//判断是否为中文字符串                
		public static function matchChinese(word:String) : Boolean 
		{
			var pattern:RegExp =/[\一-\龥]/;
			return pattern.test(word);
		}
		//匹配邮件地址               
		public static function matchEmail(email:String) : Boolean 
		{
			return pattern.test(email);
		}
		//匹配网址               
		public static function matchURL(url:String):Boolean 
		{
			var pattern:RegExp =/[a-zA-z]+:\/\/[^\s]*/; //  或者/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/
			return pattern.test(url);
		}
		//匹配电话号码              
		public static function matchPhone(phone:String):Boolean
		{
			var pattern:RegExp =/\d{3}-\d{8}|\d{4}-\d{7}/; //匹配形式如 0511-6666666 或 021-66666666
			return pattern.test(phone);
		}
		//匹配QQ号             
		public static function matchQQ(qq:String):Boolean
		{
			var pattern:RegExp =/[1-9][0-9]{4,}/;   //腾讯QQ号从10000开始
			return pattern.test(qq);
		}
		//匹配邮政编码             
		public static function matchPost(post:String):Boolean
		{
			var pattern:RegExp =/[1-9]\d{5}(?!\d)/;
			return pattern.test(post);
		}
		//匹配身份证          
		public static function matchIDcard(idcard:String):Boolean
		{
			var pattern:RegExp =/\d{15}|\d{18}/;
			return pattern.test(idcard); 
		}
		//匹配时间        
		public static function matchTime(time:String):Boolean
		{
			var pattern:RegExp =/([0-1]?[0-9]|2[0-3]):([0-5][0-9])/;
			return pattern.test(time);
		}
		//截取字符串          
		public static function interception(source:String,prefix:String,s?ix:String):String
		{
			var reg:RegExp=new RegExp("(?<="+prefix+").*?(?="+s?ix+")","s");
			var obj:String=reg.exec(source).toString();
			return obj;
		}
		//匹配多项        
		public static function matchMore(source:String,prefix:String,s?ix:String):Array
		{
			var reg:RegExp=new RegExp("(?<="+prefix+").*?(?="+s?ix+")","g");
			var obj:Array=source.match(reg)
			return obj;
		}
		//匹配数字        
		public static function matchNumber(num:String):Boolean
		{
			var pattern:RegExp =/^\d+$/;
			return pattern.test(num);
		}
		
		//匹配手机        
		public static function matchMobile(num:String):Boolean
		{
			var pattern:RegExp =/^0?1((3[0-9]{1})|(5[0-9]{1})|(8[0-9]{1})){1}[0-9]{8}$/;
			return pattern.test(num);
		}
		//校验合法时间
		public static function matchDate(num:String):Boolean
		{
			var pattern:RegExp =/\d{4}(\.|\/|\-)\d{1,2}(\.|\/|\-)\d{1,2}/; 
			return pattern.test(num);
		}
		
		//校验字符串：只能输入6-20个字母、数字、下划线(常用手校验用户名和密码)
		public static function matchStr(str:String):Boolean
		{
			var pattern:RegExp =/^(\w){6,20}$/;
			return pattern.test(str);
		}
	}
}